clear
just_figure=1;%just do figure
post_1982=0;
if post_1982==0
    b=1;
else
 b=41;
end
if just_figure==0
%load data_baseline_with_rpi;
 load data_baseline_with_rpi_solow;
data(:,1)=[data(1,1);diff(data(:,1))];
data(:,3)=[];
for i=1:2000
[~,~,usa]=bootstrap_ISTC_news(data(b:end,:),1,5,40,41,1,3,1,1,1,1,size(data,2)-1,0);
rt(:,:,i)=usa.TFP;
vt(:,:,i)=usa.weight_tfp;
cs_shock(:,i)=usa.shocks(:,1);
end
median_shock=median(cs_shock,2);
ir=median(rt,3);ir_qu=quantile(rt,[0.025,0.975],3);ir_min=nan(60,5);ir_max=nan(60,5);
vv=median(vt,3);vv_min=nan(60,5);vv_max=nan(60,5);vv_qu=quantile(vt,[0.025,0.975],3);
else
load RESULTS_SOLOW_97.5_2.5_PERCENTILES.mat    
end
h=20;
x=1:h;
figure
subplot(3,3,1),plot(x,100*ir(1:h,1),'b-',x,100*ir_qu(1:h,1,2),'b--',x,100*ir_min(1:h,1),'b:',x,100*ir_max(1:h,1),'b:',x,100*ir_qu(1:h,1,1),'b--','LineWidth',3);
title('EBP'); xlabel('Horizon');ylabel('Basis Point Deviation');
 subplot(3,3,2),plot(x,100*ir(1:h,2),'b-',x,100*ir_qu(1:h,2,2),'b--',x,100*ir_min(1:h,2),'b:',x,100*ir_max(1:h,2),'b:',x,100*ir_qu(1:h,2,1),'b--','LineWidth',3);
title('TFP'); xlabel('Horizon');ylabel('Percentage Deviation');
 subplot(3,3,3),plot(x,100*ir(1:h,3),'b-',x,100*ir_qu(1:h,3,2),'b--',x,100*ir_min(1:h,3),'b:',x,100*ir_max(1:h,3),'b:',x,100*ir_qu(1:h,3,1),'b--','LineWidth',3);
title('Output');  xlabel('Horizon');ylabel('Percentage Deviation');
subplot(3,3,4),plot(x,100*ir(1:h,4),'b-',x,100*ir_qu(1:h,4,2),'b--',x,100*ir_min(1:h,4),'b:',x,100*ir_max(1:h,4),'b:',x,100*ir_qu(1:h,4,1),'b--','LineWidth',3);
title('Investment');  xlabel('Horizon');ylabel('Percentage Deviation');
subplot(3,3,5),plot(x,100*ir(1:h,5),'b-',x,100*ir_qu(1:h,5,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,100*ir_qu(1:h,5,1),'b--','LineWidth',3);
title('Consumption'); xlabel('Horizon');ylabel('Percentage Deviation');
 subplot(3,3,6),plot(x,100*ir(1:h,6),'b-',x,100*ir_qu(1:h,6,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,100*ir_qu(1:h,6,1),'b--','LineWidth',3);
title('Hours');  xlabel('Horizon');ylabel('Percentage Deviation');
 subplot(3,3,7),plot(x,100*ir(1:h,8),'b-',x,100*ir_qu(1:h,8,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,100*ir_qu(1:h,8,1),'b--','LineWidth',3);
title('Interest Rate');  xlabel('Horizon');ylabel('Basis Point Deviation');
 subplot(3,3,8),plot(x,100*ir(1:h,7),'b-',x,100*ir_qu(1:h,7,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,100*ir_qu(1:h,7,1),'b--','LineWidth',3);
title('Inflation');  xlabel('Horizon');ylabel('Percentage Point Deviation');%legend('Median','84th and 16th Percentiles','Location', [0.70, 0.25, 0.05, 0.05]);%[Position_Right_in_pct, Position_Top_in_pct, Horizontal_Stretch, Vertical_Stretch]
set(gcf,'position',get(0,'screensize'))
if post_1982==0
 export_fig(sprintf('BZ_TFP_SOLOW_IRF.pdf'),'-transparent');
% export_fig(sprintf('BZ_TFP_SOLOW_IRF.pdf'),'-transparent');

else
export_fig(sprintf('BZ_TFP_1982_SOLOW_IRF.pdf'),'-transparent');
end
    
close all
figure
subplot(3,3,1),plot(x,vv(1:h,1),'b-',x,vv_qu(1:h,1,2),'b--',x,100*ir_min(1:h,1),'b:',x,100*ir_max(1:h,1),'b:',x,vv_qu(1:h,1,1),'b--','LineWidth',3);
title('EBP'); xlabel('Horizon');ylabel('Proportion of Forecast Error');
 subplot(3,3,2),plot(x,vv(1:h,2),'b-',x,vv_qu(1:h,2,2),'b--',x,100*ir_min(1:h,2),'b:',x,100*ir_max(1:h,2),'b:',x,vv_qu(1:h,2,1),'b--','LineWidth',3);
title('TFP'); xlabel('Horizon');ylabel('Proportion of Forecast Error');
 subplot(3,3,3),plot(x,vv(1:h,3),'b-',x,vv_qu(1:h,3,2),'b--',x,100*ir_min(1:h,3),'b:',x,100*ir_max(1:h,3),'b:',x,vv_qu(1:h,3,1),'b--','LineWidth',3);
title('Output');  xlabel('Horizon');ylabel('Proportion of Forecast Error');
subplot(3,3,4),plot(x,vv(1:h,4),'b-',x,vv_qu(1:h,4,2),'b--',x,100*ir_min(1:h,4),'b:',x,100*ir_max(1:h,4),'b:',x,vv_qu(1:h,4,1),'b--','LineWidth',3);
title('Investment');  xlabel('Horizon');ylabel('Proportion of Forecast Error');
subplot(3,3,5),plot(x,vv(1:h,5),'b-',x,vv_qu(1:h,5,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,vv_qu(1:h,5,1),'b--','LineWidth',3);
title('Consumption'); xlabel('Horizon');ylabel('Proportion of Forecast Error');
 subplot(3,3,6),plot(x,vv(1:h,6),'b-',x,vv_qu(1:h,6,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,vv_qu(1:h,6,1),'b--','LineWidth',3);
title('Hours');  xlabel('Horizon');ylabel('Proportion of Forecast Error');
 subplot(3,3,7),plot(x,vv(1:h,8),'b-',x,vv_qu(1:h,8,2),'b--',x,100*ir_min(1:h,5),'b:',x,100*ir_max(1:h,5),'b:',x,vv_qu(1:h,8,1),'b--','LineWidth',3);
title('Interest Rate');  xlabel('Horizon');ylabel('Proportion of Forecast Error');
 subplot(3,3,8),plot(x,vv(1:h,7),'b-',x,vv_qu(1:h,7,2),'b--',x,100*ir_min(1:h,5),'b:',x,vv_max(1:h,5),'b:',x,vv_qu(1:h,7,1),'b--','LineWidth',3);
title('Inflation');  xlabel('Horizon');ylabel('Proportion of Forecast Error');%legend('Median','84th and 16th Percentiles','Location',[0.70, 0.25, 0.05, 0.05]);
set(gcf,'position',get(0,'screensize'))
if post_1982==0
 export_fig(sprintf('BZ_TFP_SOLOW_FEV.pdf'),'-transparent');
% export_fig(sprintf('BZ_TFP_SOLOW_FEV.pdf'),'-transparent');

else
export_fig(sprintf('BZ_TFP_1982_SOLOW_FEV.pdf'),'-transparent');
end    

close all